package com.trkj.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.trkj.service.WorkFlowService;
import com.trkj.vo.HistoryTaskVo;
/**
 * 流程公共的控制器
 * @author Lixd
 *
 */
@Controller
@SessionAttributes({"emp", "funcIds"})
public class ProcessController {

	@Autowired
	WorkFlowService workFlowService;
	
	/**
	 * 通过流程id和流程名称查询批注
	 * @author Lixd
	 * @param processId
	 * @param processName
	 * @return
	 */
	@RequestMapping("/getFinishedComments")
	@ResponseBody
	public Map<String, Object> getFinishedComments(String processId,String processName) {
		String taskId = workFlowService.getFinishedTaskIdByProcessIdAndProcessName(processId, processName);
		if (taskId!=null) {
			return workFlowService.loadComments(taskId);
		}
		return null;
	}
	/**
	 * 直接通过任务id查询批注
	 * @author Lixd
	 * @param taskId
	 * @return
	 */
	@RequestMapping("/getAllComments")
	@ResponseBody
	public Map<String, Object> getAllComments(String taskId) {
		return workFlowService.loadComments(taskId);
	}
	/**
	 * 查询当前流程的所有任务信息(ProcessController)
	 * @author Lixd
	 * @param taskId 任务id
	 * @return
	 */
	@RequestMapping("/findAllAssignee")
	@ResponseBody
	public List<HistoryTaskVo> findAllAssignee(String taskId) {
		return workFlowService.findAllAssignee(taskId);
	}

	/**
	 * 查看图片
	 * @author Lixd
	 * @param request
	 * @param response
	 */
	@RequestMapping("/seeimg")
	public void process_img(HttpServletRequest request, HttpServletResponse response,String taskId) {
		try {
			String processInstanceId = workFlowService.getProcessInstanceIdByTaskId(taskId);
			workFlowService.queryProPlan(request, response, processInstanceId);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@RequestMapping("/deleteDeployment")
	public void deleteProcessDefinition(String did) {
		workFlowService.deleteProcessDefinition(did);
	}

}
